package com.dylan.channel.v10;


import com.dylan.channel.v10.channel.NioServerSocketChannel;
import com.dylan.channel.v10.channel.NioSocketChannel;
import com.dylan.channel.v10.handler.ChannelInitializer;
import com.dylan.channel.v10.handler.StringDecode;
import com.dylan.channel.v10.option.ChannelOption;

import java.io.IOException;
import java.nio.channels.SocketChannel;

public class NettyServerV10 {

    public static void main(String[] args) throws IOException, InterruptedException {
        NioEventLoopGroup bossGroup = new NioEventLoopGroup(1);
        NioEventLoopGroup workGroup = new NioEventLoopGroup(2);
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workGroup)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 1)
                .childHandler(new ChannelInitializer<NioSocketChannel>() {
                    @Override
                    protected void initChannel(NioSocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new StringDecode())
                                .addLast(new StringDecode());
                    }
                });
        bootstrap.bind(8086).sync();
    }
}
